package com.laot.search.controller;

import com.laot.search.manager.SearchFacade;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.laot.seacher_master.model.common.BaseResponse;
import org.laot.seacher_master.model.common.ResultUtils;
import org.laot.seacher_master.model.dto.search.SearchRequest;
import org.laot.seacher_master.model.vo.SearchVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 聚合搜索
 *
 * @author laoT
 */
@RestController
@RequestMapping("/search")
@Slf4j
@Api(tags = "聚合搜索")
public class SearchController {

    @Resource
    private SearchFacade searchFacade;

    @PostMapping("/all")
    public BaseResponse<SearchVO> searchAll(@RequestBody SearchRequest searchRequest, HttpServletRequest request) {
        if(searchRequest.getCurrent() == 0) searchRequest.setCurrent(1);
        if(searchRequest.getPageSize() == 0) searchRequest.setPageSize(20);
        return ResultUtils.success(searchFacade.searchAll(searchRequest,request));
    }

}
